package android.slc.base.vm;

import android.slc.base.vmsub.WindowShareVm;
import android.slc.commonlibrary.CacheMemoryUtils;
import android.slc.fast.vm.ShareViewModel;
import android.slc.module.component.dict.vmbox.TreeDictShareVm;

/**
 * 全局数据
 *
 * @author slc
 * @date 2020-08-18 17:37
 */
public class GlobalDataVm extends ShareViewModel {
    private static final GlobalDataVm globalDataVm = new GlobalDataVm();
    public final TreeDictShareVm treeDictShareVm = new TreeDictShareVm();

    private final CacheMemoryUtils baseCacheMemoryUtils = CacheMemoryUtils.getInstance("baseCache", 512);
    public final WindowShareVm windowShareVm = new WindowShareVm();

    public static GlobalDataVm getInstance() {
        return globalDataVm;
    }

    public <T> T getData(String key) {
        return baseCacheMemoryUtils.get(key);
    }

    public void putData(String key, Object value) {
        baseCacheMemoryUtils.put(key, value);
    }

    public void clearAllData() {
        baseCacheMemoryUtils.clear();
        treeDictShareVm.onCleared();
    }

    @Override
    public void clearShare() {
        super.clearShare();
        clearAllData();
    }
}
